package com.park.web.controller.admin;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.park.client.model.exam.ExamPaperTypeModel;
import com.park.client.model.exam.ExamPaperTypeDetailModel;
import com.park.client.service.exam.ExamPaperTypeDetailService;
import com.park.client.service.exam.ExamPaperTypeService;
import com.park.common.util.Page;
import com.park.common.util.PageData;
import com.park.common.util.Result;
import com.park.web.contant.Global;
import com.park.web.controller.BaseController;

@Controller
@RequestMapping("/admin/exam")
public class AdminExamController extends BaseController{

	@Autowired
	private ExamPaperTypeService examSubjectService;
	
	@Autowired
	private ExamPaperTypeDetailService examSubjectPaperService;
	
	/**
	 * 试卷分类页面
	 */
	@RequestMapping("examSubjectList")
	public String examSubjectList(HttpServletRequest request){
		return Global.ADMIN_PATH+"exam/examSubjectList";
	}
	
	/**
	 * 试卷分类
	 */
	@RequestMapping("listExamSubjectRows")
	@ResponseBody
	public Result<List<ExamPaperTypeModel>> listExamSubjectRows(){
		Result<List<ExamPaperTypeModel>> result = new Result<>(true);
		ExamPaperTypeModel subjectModel = new ExamPaperTypeModel();
		result.setObj(this.examSubjectService.selectPagination(subjectModel));
		return result;
	}
	
	/**
	 *试卷列表 
	 */
	@RequestMapping("listExamPaperRows")
	@ResponseBody
	public PageData<ExamPaperTypeDetailModel> listExamPaperRows(Integer rows,@RequestParam(name="page",defaultValue="1")Integer pageNow,HttpServletRequest request){
		PageData<ExamPaperTypeDetailModel>  pageData = new PageData<>();
		ExamPaperTypeDetailModel paperModel = new ExamPaperTypeDetailModel();
		Integer total = examSubjectPaperService.selectTotal(paperModel);
		Page page = new Page(pageNow,total,rows);
		paperModel.setStartPos(page.getStartPos());
		paperModel.setPageSize(page.getPageSize());
		List<ExamPaperTypeDetailModel> list = examSubjectPaperService.selectPagination(paperModel);
		pageData.setTotal(total);
		pageData.setRows(list);
		return pageData;
	}
	
	
	/*@RequestMapping("listExamSubjectRows")
	@ResponseBody
	public PageData<ExamSubjectModel> listExamSubjectRows(Integer rows,@RequestParam(name="page",defaultValue="1")Integer pageNow,HttpServletRequest request){
		PageData<ExamSubjectModel>  pageData = new PageData<>();
		ExamSubjectModel subjectModel = new ExamSubjectModel();
		Integer total = examSubjectService.selectTotal(subjectModel);
		Page page = new Page(pageNow,total,rows);
		subjectModel.setStartPos(page.getStartPos());
		subjectModel.setPageSize(page.getPageSize());
		List<ExamSubjectModel> list = examSubjectService.selectPagination(subjectModel);
		pageData.setTotal(total);
		pageData.setRows(list);
		return pageData;
	}*/
	
//	/**
//	 * 试卷类别明细
//	 */
//	@RequestMapping("examPaperList/{examSubjectId}")
//	public String examPaperList(@PathVariable("examSubjectId")Long examSubjectId,@RequestParam(name="pageNow",defaultValue="1")Integer pageNow,HttpServletRequest request){
//		ExamSubjectPaperModel paperModel = new ExamSubjectPaperModel();
//		paperModel.setExamSubjectId(examSubjectId);
//		Integer total = examSubjectPaperService.selectTotal(paperModel);
//		Page page = new Page(pageNow,total,10);
//		paperModel.setStartPos(page.getStartPos());
//		paperModel.setPageSize(page.getPageSize());
//		List<ExamSubjectPaperModel> subjectPaperModels = examSubjectPaperService.selectPagination(paperModel);
//		request.setAttribute("subjectPaperModels", subjectPaperModels);
//		request.setAttribute("page", page);
//		return Global.PUBLIC_PATH+"exam/examPaperList";
//	}
	
}
